package com.smf.lsc.database.config;

import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.smf.lsc.database.filter.ResultSetLimitFilter;

/**
 * 大结果集限制
 * 避免一次性查询超大结果集时，会造成内存溢出问题，导致服务不可用
 * 使用条件：
 * 1、需要配置JDBC URL的 &useCursorFetch=true&defaultFetchSize=300000 参数才可以，否者mybaits仍然会加载全部数据至客户端内存
 * @author ln
 */
@Configuration
@ConditionalOnProperty(prefix = "spring.datasource.resultsetlimit", name = "enable", havingValue = "true")
public class ResultSetLimitConfig {

	@Bean
	@ConditionalOnMissingBean(ResultSetLimitFilter.class)
	public ResultSetLimitFilter rowLimitFilter() {
		return new ResultSetLimitFilter();
	}

}
